package com.aaron.gesturehelper.gesturelib;

public class MySingleInstance extends MyInstance {

    // the feature vector
    private float[] vector;
    
	MySingleInstance(long id, String label, int type, float[] vector) {
		super(id, label, type);
		this.vector = vector;
	}

    private void normalize() {
        float[] sample = vector;
        float sum = 0;

        int size = sample.length;
        for (int i = 0; i < size; i++) {
            sum += sample[i] * sample[i];
        }

        float magnitude = (float)Math.sqrt(sum);
        for (int i = 0; i < size; i++) {
            sample[i] /= magnitude;
        }
    }

	public static MyInstance newInstance(MyGesture gesture, String label) {
		float[] pts = MyGestureUtil.temporalSampler(gesture.getStrokes().get(0));
		MySingleInstance instance = new MySingleInstance(gesture.getID(),label, 1, pts);
		instance.normalize();
		return instance;
	}

	@Override
	public double compareTwoInstance(MyInstance other) {
		MySingleInstance second = (MySingleInstance) other;	
		return MyGestureUtil.minimumCosineDistance(vector, second.vector, 8);
	}	
}
